home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-21 | 2.4 KB | 82 lines | [TEXT/RLAB] |
- getline:
-
- Syntax: getline ( "filename" )
-
- Description:
-
- Getline returns an N-element list which contains all of the
- tokens from a line in the file described by "filename". The
- tokens are delimited by whitespace. Numbers are installed in
- the list as numeric scalars, everything else is installed as
- scalar strings.
-
- The list elements have numeric indices, and are numbered from
- 1 to N. The 1st element containing the 1st token on the line,
- and the Nth element containing the last token on the line. The
- newline is not returned as a token.
-
- Getline will also recognize everything enclosed within a pair
- of `"' as a string, including escape characters.
-
- Getline will always return a list-object. When an empty-line
- has been read, getline returns an empty list. Getline will
- terminate on an End-Of-File (EOF).
-
- The filename can be a string that specifies a sub-process (see
- `help FILES'), in which case getline() will run the
- sub-process, and read from the process's standard output.
-
- Examples:
-
- To get input interactively:
-
- > printf( "Enter a string and a number: " ); x = getline( "stdin" );
- Enter a string and a number: test-string 1.234e5
- > show(x)
- name: x
- class: list
- n: 2
- > x.[1]
- test-string
- > x.[2]
- 2 =
- 1.23e+05
-
- Given a file named `test', which contains the following lines:
-
- jcool 259 4 1075 822 vt01 S Dec 29 9:32 X :0 -p 1 -s 5
- jcool 256 0 21 0 console S Dec 29 0:00 startx
- jcool 261 0 338 88 console S Dec 29 0:16 twm
- jcool 288 8 635 333 ? S Dec 29 2:00 emacs
- jcool 287 0 408 65 console S Dec 29 0:01 xclock
-
- tmp = getline( "test" );
-
- would produce a list variable named `tmp' with 16 elements:
- tmp.[1] would be the string "jcool" and tmp.[16] would be the
- number 5. The next call to getline() would read the second
- line in the file, and create a new list containing those
- elements.
-
- The above could also have been done with:
-
- tmp = getline( "|ps -aux | grep jcool" )
-
- Which would open a readable pipe to the "ps -aux | grep jcool"
- command and grab a line at a time from the process.
-
- To read the entire contents of a file:
-
- if (length (ans = getline("stdin")))
- {
- // do something with ans
- else
- // finish up
- }
-
- Since getline returns an empty list when there is no input, we
- can tell when to terminate the input loop by checking the
- length of the returned list.
-
- See Also: FILES, LIST
-